package com.shuangdj.databinding;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.shuangdj.databinding.bean.TestModel;
import com.shuangdj.databinding.bean.TestParentModel;
import com.shuangdj.databinding.databinding.ActivityMainBinding;
import com.shuangdj.databinding.presenter.TestPresenter;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements TestPresenter.Refresh {
    TestParentModel test;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TestPresenter testPresenter = new TestPresenter();
        testPresenter.setRefresh(this);
        ActivityMainBinding binding = DataBindingUtil
                .setContentView(this, R.layout.activity_main);
        TestModel testModel = new TestModel("hello data_binding");
        binding.setTest(testModel);
        binding.setTestPresenter(testPresenter);
        test = new TestParentModel();
        binding.setTestParent(test);
        testPresenter.getData();
    }


    @Override
    public void onRefresh(ArrayList<TestModel> testModels) {
        test.setTestModels(testModels);
    }
}
